package com.wan37.logic.listener.handler;

import com.wan37.logic.global.reference.SpringContextHolder;
import com.wan37.logic.guild.cache.GuildCache;
import com.wan37.logic.guild.domain.vo.GuildUserVO;
import com.wan37.logic.listener.annotation.EventHandler;
import com.wan37.logic.listener.annotation.Listener;
import com.wan37.logic.listener.event.EventType;
import com.wan37.logic.listener.event.user.UserLoginEvent;
import com.wan37.logic.service.cache.UserServiceCache;
import com.wan37.protobuf.message.client2server.game.GameGuild;

/**
 * @author : luoyong
 * @date : 2020-08-04 17:27
 **/
@Listener
public class GuildListenerHandler {
    private UserServiceCache userServiceCache;
    private GuildCache guildCache;
    public GuildListenerHandler(){
        this.guildCache = SpringContextHolder.getBean("guildCache");
        this.userServiceCache = SpringContextHolder.getBean("userServiceCache");
    }
    @EventHandler(EventType.LOGIN)
    public void login(UserLoginEvent userLoginEvent){
        for (GuildCache.GuildIn guildIn : guildCache.getGuildInMap().values()){
            for (GuildUserVO guildUserVO : guildIn.getGuildUserVOList()){
                if (guildUserVO.getUserId().equals(userLoginEvent.getUserId())){
                    userServiceCache.getUserServiceMap().get(userLoginEvent.getUserId()).setGuildId(guildUserVO.getGuildId());
                    break;
                }
            }
        }
    }
}
